<template>
	<view class="mainpadding">
		<view class="mainpadding_top ffffff radius">
			<textarea placeholder="请输入内容~" style="width: 100%;height: 200rpx;" v-model="des"></textarea>
			<view class="margin_top titletext bold hei_text">赛事图片</view>
			<view class="flexleft flex_wrap">
				<view class="shilitu margin_top margin_right2 dingwei" v-for="(item,index) in images_text"
					:key="index">
					<image :src="item" mode=""></image>
					<view class="shanchu" @click="delindex(index,images_text,images)">
						<u-icon name="close-circle-fill"></u-icon>
					</view>
				</view>
				<view class="margin_top shangc margin_right2" v-if="images_text.length<3"
					@click="uploadImg(3,images,images_text)">
					<image src="../static/image/system/shangchuan.png" mode=""></image>
				</view>
			</view>
			<view class="margin_top titletext bold hei_text">赛事视频</view>
			<view class="upzhizhao margin_top flexcenter" v-if="!video_url" @click="upvideo()">
				<u-icon name="plus" color="#999" size="28"></u-icon>
			</view>
			<view v-if="video_url" class="upzhizhao margin_top" style="position: relative;">
				<video :src="video_url_text" object-fit="cover" class="upzhizhao" data-id="video" id="video"></video>
				<view class="shanchu" @click="delvideo()">
					<u-icon name="close-circle-fill"></u-icon>
				</view>
			</view>
		</view>
		<view class="gudingdb mainpadding">
			<view class="bigbtn" @click="submit()">提交</view>
		</view>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				images: [],
				images_text: [],
				listid:"",
				des:"",
				video_url_text:"",
				video_url:""
			}
		},
		onLoad(options) {
			this.listid = options.id
		},
		methods: {
			delvideo(val) {
				this.video_url_text = ""
				this.video_url = ""
			},
			upvideo(val) { //上传视频
				let uploadFile = ''
				let _this = this;
				// 1.选择要上传的视频
				uni.chooseVideo({
					maxDuration: 60, // 拍摄视频最长拍摄时间，单位秒。最长支持 60 秒。
					sourceType: ['album', 'camera'], // album 从相册选视频，camera 使用相机拍摄，默认为：['album', 'camera']
					success: function(res) {
						_this.uploadImageServicet(res.tempFilePath)
					}
				});
			},
			uploadImageServicet(url, upImg, upImgs_text) {
				let _this = this;
				httpRequest.uploadFile('/api/common/upload', url).then(res => {
					let image_item = res.fullurl;
						this.video_url = res.url
						this.video_url_text = image_item
			
				}).catch(err => {});
			},
			submit(){
				if(this.des==""){
					httpRequest.toast("请输入评价内容！")
					return false
				}
				let data = {
					ss_bm_id:this.listid,
					des:this.des,
					images:this.images.join(),
					video_url:this.video_url
				}
				let url = "/api/user/uploadSsJj"
				httpRequest.request(url, 'POST', data, false, false, true).then(res => {
					httpRequest.toast(res.msg)
					if (res.code == 1) {
						setTimeout(()=>{
							uni.navigateBack(1)
						},1000)
					}
				})
			},
			uploadImg(value, upImgs, upImgs_text) { //上传图片
				let _this = this;
				let num =  Number(value) - upImgs.length;
				if (num <= 0) {
					return false;
				}
				uni.showActionSheet({
					itemList: ['相机', '相册'],
					success: function(res) {
						// 选择相机走0
						if (res.tapIndex == 0) {
							httpRequest.chooseImage(num, ['camera']).then(res => {
								for (var i = 0; i < res.length; i++) {
									_this.uploadImageService(res[i], upImgs, upImgs_text)
								}
							}).catch(err => {});
						}
						// 选择相册走1
						if (res.tapIndex == 1) {
							httpRequest.chooseImage(num, ['album']).then(res => {
								for (var i = 0; i < res.length; i++) {
									_this.uploadImageService(res[i], upImgs, upImgs_text)
								}
							}).catch(err => {});
						}
					},
					fail: function(res) {}
				});
			},
			delindex(index, upImg, upImgs_text) {
				upImg.splice(index, 1)
				upImgs_text.splice(index, 1)
			},
			uploadImageService(url, upImg, upImgs_text) {
				let _this = this;
				httpRequest.uploadFile('/api/common/upload', url).then(res => {
					let image_item = res.fullurl;
					upImg.push(res.url)
					upImgs_text.push(image_item);
				}).catch(err => {});
			},
		}
	}
</script>

<style lang="scss" scoped>
	page{
		background-color: #f9f9f9;
	}
	.shangc {
		width: 160rpx;
		height: 160rpx;
	
		image {
			width: 100%;
			height: 100%;
		}
	}
	.shanchu {
		position: absolute;
		top: -10rpx;
		right: -10rpx;
	}
	
	.shanchu2 {
		position: absolute;
		bottom: -10rpx;
		right: -50%;
		transform: translate(0, -50%);
	}
	
	.shilitu {
		width: 160rpx;
		height: 160rpx;
	
		image {
			width: 100%;
			height: 100%;
		}
	}
</style>
